"""
NC103 反转字符串
https://www.nowcoder.com/practice/c3a6afee325e472386a1c4eb1ef987f3?tpId=117&&tqId=37827&&companyId=239&rp=1&ru=/company/home/code/239&qru=/ta/job-code-high/question-ranking
"""
#
# 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
#
# 反转字符串
# @param str string字符串
# @return string字符串
#
class Solution:
    def method1(self, s: str) -> str:
        """
        只适合python的解法
        """
        return s[::-1]

    def method2(self, s: str) -> str:
        """
        对撞指针
        时间复杂度：O(n)
        空间复杂度：O(n)
        """
        l, r = 0, len(s)-1
        lst = ['']*len(s)

        while l <= r:
            if l == r:
                lst[l] = s[l]
                break

            lst[l] = s[r]
            lst[r] = s[l]
            r -= 1
            l += 1

        return "".join(lst)

    def solve(self, s: str) -> str:
        # write code here
        if len(s) <= 1:
            return s

        return self.method2(s)


def test():
    obj = Solution()
    s = "abcd"
    res = obj.solve(s)
    print(res)


if __name__ == "__main__":
    test()
